/**
 * 树形控制器 包含常量及常用操作
 * @type 
 */
function NoeZTreeControl_OP(){
	this.IDMark_A = "_a";
	this.zTreeControlName = "";
	this.ctxPath = ""; //项目上下文
	this.noeZTreeControl = null; //树 控制器
	this.onClickByUser = null; // 用户定义的click操作，用来复写 原有的click操作
	this.onAsyncSuccessFun = null; //用户 定义的  异步加载成功函数
	this.rightMenuNames = null;//每一层树结构涉及的右键菜单名称
	this.RightTargetID = ""; //treenode的ID
	this.rightMenuMap = null;//右键菜单 集合映射
	this.RightMenuCurrentTreeNodeObj = null; //当前右键菜单触发的 node对象 {event : event, treeId : treeId, treeNode : treeNode}
	this.enableRightSysMenu = true;//系统自带右键菜单是否启用
	this.sumSubChildLevel = 0;//  可以添加多少级下级菜单
	this.isAsyncTreeNode = false; //该树是否是异步树（一次性加载所有节点）
	this.treeConstCodeArr = null; //树 对应的常量code
	this.currentEditNode = null;//当前正在编辑的节点
	this.currentPageIsReflush = true;//当前页面是否已经刷新,
	this.actionName = "";//当前操作树的action
	this.selectIndirModel = "_selectID";
	
	/**
	 * 得到系统自定义的的右键菜单
	 */
	this.getSystemRMenu = function(index,event, treeNode, treeId){
		var arr = new Array();
		
		var mainMenuName = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).getMenuNameByIndex(index);
		
		//menuType = 0 属于 系统右键菜单
		
		//最后 一层 叶子 不需要插入下级节点
		if(treeNode.level < NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).sumSubChildLevel-1){
			var subMenuName = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).getMenuNameByIndex(index+1);
			arr.push({menuType : 0,menuName : "插入下级"+subMenuName, menuClick : this.getControlAndCPName()+".getSystemMenuClickFun('add-sub')" });
		}
		
		arr.push({menuType : 0,menuName : "在前面插入同级"+mainMenuName, menuClick : this.getControlAndCPName()+".getSystemMenuClickFun('add-before')" });
		arr.push({menuType : 0,menuName : "在后面插入同级"+mainMenuName, menuClick : this.getControlAndCPName()+".getSystemMenuClickFun('add-after')"});
		
		return arr;
	};
	
	/**
	 * 注册 系统右键菜单触发方法
	 * @param {} biaos
	 * @return {}
	 */
	this.getSystemMenuClickFun = function(biaos){ 
		if(!biaos){
			return null;
		}
		
		if(biaos == "add-before"){
			this.showAddNodeFormByRMenu(biaos);
		}else if(biaos == "add-after"){
			this.showAddNodeFormByRMenu(biaos);
		}else if(biaos == "add-sub"){
			this.showAddNodeFormByRMenu(biaos);
		}
		
	};
	
	
	this.createRightMenu = function(index,rMenuArr){
		if(!this.rightMenuMap){
			this.rightMenuMap = new Map();
		}
		
		if(this.rightMenuMap.get(index)){
			this.rightMenuMap.remove(index);
		}
		
		this.rightMenuMap.put(index,rMenuArr);
	};
	
	/**
	 * 得到 每一层 涉及菜单对象的名称
	 * @param {} index
	 */
	this.getMenuNameByIndex = function(index){ 
		if(this.rightMenuNames){
			if(this.rightMenuNames.length-1 >= index){
				return this.rightMenuNames[index];
			}else{
				return this.rightMenuNames[this.rightMenuNames.length-1];
			}
		}
		return "";
	};
	
	/**
	 * 鼠标移上去 出现的操作
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.addHoverDom = function(treeId, treeNode){ 
		
		var aObj = $("#" + treeNode.tId + NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).IDMark_A);
		var arr = new Array();
		
		if(treeNode.flagUse == 0){ //显示 恢复 超连接
			if ($("#diyBtn_rec_"+treeNode.id).length>0){
				return;	
			}
						
			arr.push("<a href='javascript:void(0);' style='color: blue;text-decoration: underline' id='diyBtn_rec_" +treeNode.id+ "''>恢复</a>");
			for(i in arr){
				aObj.after(arr[i]);
			}
			
			var recBtn = $("#diyBtn_rec_"+treeNode.id);
			if (recBtn){
				recBtn.bind("click", function(){
					NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).recNode(treeNode,treeId);
				});
			}
			
			return;
		}
	
		if ($("#diyBtn_des_"+treeNode.id).length>0 || $("#diyBtn_asc_"+treeNode.id).length>0 || $("#diyBtn_del_"+treeNode.id).length>0 || $("#diyBtn_edit_"+treeNode.id).length>0){
			return;
		}
		
		if(treeNode.getNextNode() && treeNode.getNextNode().flagUse == 1){
			arr.push("<a href='javascript:void(0);' id='diyBtn_des_" +treeNode.id+ "'><img  title='降序' src='"+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).ctxPath+"/static/js/zTree/selfImage/i_des.gif'></a>");
		}
		
		if(treeNode.getPreNode()){
			arr.push("<a href='javascript:void(0);' id='diyBtn_asc_" +treeNode.id+ "'><img  title='升序' src='"+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).ctxPath+"/static/js/zTree/selfImage/i_asc.gif'></a>");
		}
		
		arr.push("<a href='javascript:void(0);' id='diyBtn_del_" +treeNode.id+ "''><img  title='删除' src='"+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).ctxPath+"/static/js/zTree/selfImage/icon_del.gif'></a>");
		arr.push("<a href='javascript:void(0);' id='diyBtn_edit_" +treeNode.id+ "'><img  title='编辑' src='"+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).ctxPath+"/static/js/zTree/selfImage/icon_edit.gif'></a>");
		
//		var splitStr = "<span class=''></span>";
//		aObj.append(splitStr );
		
		for(i in arr){
			aObj.after(arr[i]);
		}
		
		var desBtn = $("#diyBtn_des_"+treeNode.id);
		if (desBtn){
			desBtn.bind("click", function(){
				NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).desNode(treeNode,treeId);
			});
		}
		
		var ascBtn = $("#diyBtn_asc_"+treeNode.id);
		if (ascBtn){
			ascBtn.bind("click", function(){
				NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).ascNode(treeNode,treeId);
			});
		}
		
		var delBtn = $("#diyBtn_del_"+treeNode.id);
		if (delBtn){
			delBtn.bind("click", function(){
				NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).deleteNode(treeNode,treeId);
			});
		}
		
		var editBtn = $("#diyBtn_edit_"+treeNode.id);
		if (editBtn){
			editBtn.bind("click", function(){
				NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).editNode(treeNode,treeId);
			});
		}
	
	};
	
	/**
	 * 编辑节点
	 * @param {} treeNodeTID
	 */
	this.editNode = function(treeNode,treeId){
		NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).currentEditNode = treeNode;
		NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).showAddNodeFormByRMenu("edit-node");
	};
	
	/**
	 * 删除节点
	 * @param {} treeNodeTID
	 */
	this.deleteNode = function(node,treeId){ 
		
		var FData = {nodeID : node.id};
		$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).actionName+"!deleteTreeNode.do",FData,function(res){ 
				eval("var text="+res);
				if(text.success){
					NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).reAsyncChildNode(node.getParentNode(),"refresh");
					return ;
				}else{
					 alert("操作失败，请重试!");
					return ;
				}
		});
		
//		this.noeZTreeControl.zTree.removeNode(node);
	};
	
	/**
	 * 节点升序
	 * @param {} treeNodeTID
	 */
	this.ascNode = function(treeNode,treeId){
		var FData = {nodeID : treeNode.id, dir : 'asc'};
		$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).actionName+"!scTreeOrder.do",FData,function(res){ 
				eval("var text="+res);
				if(text.success){
					NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).reAsyncChildNode(treeNode.getParentNode(),"refresh");
					return ;
				}else{
					 alert("操作失败，请重试!");
					return ;
				}
		});
	};
	
	/**
	 * 节点降序
	 * @param {} treeNodeTID
	 */
	this.desNode = function(treeNode,treeId){
		var FData = {nodeID : treeNode.id, dir : 'dsc'};
		$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).actionName+"!scTreeOrder.do",FData,function(res){ 
				eval("var text="+res);
				if(text.success){
					NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).reAsyncChildNode(treeNode.getParentNode(),"refresh");
					return ;
				}else{
					 alert("操作失败，请重试!");
					return ;
				}
		});
	};
	
	/**
	 * 恢复删除的节点
	 * @param {} treeNode
	 */
	this.recNode = function(treeNode,treeId){
		var FData = {nodeID : treeNode.id};
		$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).actionName+"!recoveryTreeNode.do",FData,function(res){ 
				eval("var text="+res);
				if(text.success){
					NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).reAsyncChildNode(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).getRecReflshNode(treeNode),"refresh");
					return ;
				}else{
					 alert("操作失败，请重试!");
					return ;
				}
		});
	};
	
	/**
	 * 恢复时  需要递归得到其最上层级  被删除的节点，从而来加载刷新树
	 * @param {} treeNode
	 * @return {}
	 */
	this.getRecReflshNode = function(treeNode){
		var parentNode = treeNode.getParentNode();
		
		if(!parentNode){
			return null;
		}
		
		if(parentNode.flagUse == 1){
			return parentNode;
		}
		
		return this.getRecReflshNode(parentNode);
	};
	
	/**
	 * 根据tid得到节点
	 * @param {} treeNodeTID
	 */
	this.getNodeByTID = function(treeNodeTID){
		return this.noeZTreeControl.zTree.getNodeByTId(treeNodeTID);
	};
	
	/**
	 * 鼠标移出焦点后 操作
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.removeHoverDom = function(treeId, treeNode){ 
		if(treeNode.flagUse == 0){
			$("#diyBtn_rec_"+treeNode.id).unbind().remove();
			return;
		}
		$("#diyBtn_des_"+treeNode.id).unbind().remove();
		$("#diyBtn_asc_"+treeNode.id).unbind().remove();
		$("#diyBtn_del_"+treeNode.id).unbind().remove();
		$("#diyBtn_edit_"+treeNode.id).unbind().remove();
	};
	
	/**
	 * 异步加载成功函数
	 * @param {} event
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.onAsyncSuccess = function(event, treeId, treeNode){
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.check){
			if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.check.enable){
			
			if(treeNode.childs){
				    for(var i=0; i<treeNode.childs.length; i++){
				    	NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.checkNode(treeNode.childs[i],treeNode.checked,false,false);
					}
				}
			}
		}
		
		if(!treeNode){
			return;
		}
		
		var nodes = treeNode.childs; 
		if(!nodes){
			return;
		}
		
		for(var i=0; i<nodes.length; i++){
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.reAsyncChildNodes(nodes[i],"refresh");
		}
	};
	
	
	/**
	 * 异步加载成功函数[check tree]第一次加载 需要全部展开时 调用的加载函数
	 * @param {} event
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.onCheckedAsyncSuccess = function(event, treeId, treeNode){
		
		if(!treeNode){
			return;
		}
		
		var nodes = treeNode.childs; 
		if(!nodes){
			return;
		}
		
		for(var i=0; i<nodes.length; i++){
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.reAsyncChildNodes(nodes[i],"refresh");
		}
	};
	
	/**
	 * 树的 click操作
	 * @param {} event
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.onClick = function(event, treeId, treeNode){ 
		
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.callback){
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.callback.onAsyncSuccess = this.onAsyncSuccessFun;
		}else{
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.callback.onAsyncSuccess = null;
		}
		
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).onClickByUser){
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).onClickByUser(event, treeId, treeNode);
		}
		
	};
	
	/**
	 * 右键菜单事件
	 * @param {} event
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.onRightClick = function(event, treeId, treeNode){
		if(treeNode){
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).RightMenuCurrentTreeNodeObj = {event : event, treeId : treeId, treeNode : treeNode};
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).showRMenu(event, treeId, treeNode);
		}else{
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).RightMenuCurrentTreeNodeObj = null;
		}
	};
	
	/**
	 * 右键菜单触发之前
	 * @param {} treeId
	 * @param {} treeNode
	 * @return {Boolean}
	 */
	this.beforeRightClick = function(treeId, treeNode){
		return true;
	};
	
	/**
	 * 展示右键菜单层
	 * @param {} event
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.showRMenu = function(event, treeId, treeNode){
		
		if(treeNode.flagUse == 0){ //被删除的数据，禁用右键菜单
			return;
		}
		
		//如果启用了系统自带右键菜单,开始初始化
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).enableRightSysMenu){
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).createRightMenu(treeNode.level,NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).getSystemRMenu(treeNode.level,event,treeNode,treeId));
		}
		
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).rightMenuMap){
			var menuArr = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).rightMenuMap.get(treeNode.level);
			
			if(!menuArr){
				menuArr = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).rightMenuMap.get(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).rightMenuMap.size()-1);
			}
			
			if(menuArr){
				
			   NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).RightTargetID = treeNode.id; //用数据库key  来作为页面触发对象
					
				var divHtmlObj = $("<div id='rMenu'></div>");
				var ulHtmlObj = $("<ul></ul");
				ulHtmlObj.appendTo(divHtmlObj);
				
				for(var i=0; i<menuArr.length; i++){
					var menu = menuArr[i];
					var liHtmlObj = $("<li id=\"m_add\" onclick=\"javascript:" 
					        + this.getControlAndCPName()+".menuClickFilter();"
							+ menu.menuClick+";"
							+ "\" >"+menu.menuName+"</li>");
					liHtmlObj.appendTo(ulHtmlObj);
				}
				
				divHtmlObj.appendTo($("body"));
				
				divHtmlObj.children().show();
				divHtmlObj.css({"top": event.clientY+"px", "left": event.clientX+"px", "visibility":"visible", "z-index":"10000"});
				
				$("body").attr("treeId",treeId);
				$("body").bind("mousedown", NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).onBodyMouseDown);
			}
		}
		
	};
	
	/**
	 * 右键菜单事件过滤器
	 */
	this.menuClickFilter = function(){
		this.hideRMenu();
	};
	
	/**
	 * 隐藏右键菜单
	 */
	this.hideRMenu = function(){
		
		var rMenu = $("#rMenu");
		if (rMenu){
//			rMenu.css({"visibility": "hidden"});
			rMenu.remove();
		}
	};
	
	/**
	 * 鼠标单击  移出单击操作
	 * @param {} event
	 */
	this.onBodyMouseDown = function(event){ 
		if (!(event.target.id == this.RightTargetID || $(event.target).parents("#rMenu").length>0 )) {
				$("body").unbind("mousedown", this.onBodyMouseDown);
				NoeZTreeControl_OP_Map.getCurrentControl_OP($("body").attr("treeId")).hideRMenu();
		}
	};
	
	/**
	 * 通过右键菜单 增加节点
	 * @param {} bz  标识  前/后  before/after
	 */
/*	addNodeByRMenu : function(bz,formDivID){
		if(!bz){
			bz = "";
		}
		
		//隐藏右键菜单
		this.hideRMenu();
		
		if(bz == "before"){
			this.showAddNodeFormByRMenu(bz,formDivID);
		}else if(bz == "after"){
			this.showAddNodeFormByRMenu(bz,formDivID);
		}
		
	},*/
	
	/**
	 * 增加的表单界面
	 * @param {} bz
	 */
	this.showAddNodeFormByRMenu = function(bz){
		if(bz == "add-before"){
			this.createAdddNodeFormByRMenu(bz);
//			$("#ZtreeMenuDivID").css({"display" : "block"});
		}else if(bz == "add-after"){
			this.createAdddNodeFormByRMenu(bz);
//			$("#ZtreeMenuDivID").css({"display" : "block"});
		}else if(bz == "add-sub"){
			this.createAdddNodeFormByRMenu(bz);
//			$("#ZtreeMenuDivID").css({"display" : "block"});
		}else if(bz == "add-top"){
			this.createAdddNodeFormByRMenu(bz);
//			$("#ZtreeMenuDivID").css({"display" : "block"});
		}else if(bz == "edit-node"){
			this.createAdddNodeFormByRMenu(bz);
//			$("#ZtreeMenuDivID").css({"display" : "block"});
		}
	};
	
	/**
	 * 生成 添加页面的 html
	 * @param {} bz
	 */
	this.createAdddNodeFormByRMenu = function(bz){
		var menuName = "";
		var menuValue = "";
		if(bz == "add-before"){
			menuName = this.getMenuNameByIndex(this.RightMenuCurrentTreeNodeObj.treeNode.level);
		}else if(bz == "add-after"){
			menuName = this.getMenuNameByIndex(this.RightMenuCurrentTreeNodeObj.treeNode.level);
		}else if(bz == "add-sub"){
			menuName = this.getMenuNameByIndex(this.RightMenuCurrentTreeNodeObj.treeNode.level + 1);
		}else if(bz == "add-top"){
			menuName = this.getMenuNameByIndex(0);
		}else if(bz == "edit-node"){
			menuName = this.getMenuNameByIndex(this.currentEditNode.level);
			menuValue = this.currentEditNode.name;
		}
		
		var treeID = this.noeZTreeControl.zTree.setting.treeId;
		
	/*	var arr = new Array();
		arr.push('<div id="ZtreeMenuDivID" style="display: none;">');
		
		
		arr.push('<div id="light" class="pop tac mt15 mb10" style="width: 400px;height:160px; display: block;"> ');
		
		arr.push(' <h1 class="pdlev10 fs14">'+menuName+'维护');
		arr.push(' <span class="fr"><a href="javascript:void(0)" onClick="'+this.getControlAndCPName()+'.removeAdddNodeFormByRMenu(\''+bz+'\')"><img src="'+this.ctxPath+'/static/js/zTree/selfImage/i_close.gif" alt="关闭" /></a></span>');
		arr.push(' </h1>');
		
		arr.push('<div class="content">');
		arr.push('  <div class="userli clear"> ');
		arr.push(menuName+'名称'+'：<input type="text" id="menuNameInputID" class="itext" value="'+menuValue+'" /> ');
		arr.push('  </div>');
		arr.push('  <div class="btn mt25 tac clear"><input class="itext" name="" type="button" value="确定" onclick="'+this.getControlAndCPName()+'.saveFormNodeByRMenu(\''+bz+'\',\''+treeID+'\');"/> <input class="itext" name="" type="button" value="取消" onclick="'+this.getControlAndCPName()+'.cancelFormNodeByRMenu(\''+bz+'\',\''+treeID+'\');"/></div> ');
		arr.push('</div>');
		
		arr.push('</div>');
		
		
		arr.push('<div id="fade" class="black_overlay" style="display: block;"></div>    ');
		arr.push('</div>');
		
		var html = arr.join("");
		$(html).appendTo($("body"));*/
		
		this.showModel(menuName,menuValue,this.noeZTreeControl.zTree.setting.treeId,bz );
	};
	
	this.getControlAndCPName = function(){
		return this.zTreeControlName+".NoeZTreeCP";
	};
	
	/**
	 * 隐藏 添加 界面
	 * @param {} bz
	 */
	this.removeAdddNodeFormByRMenu = function(bz){
		if(bz == "add-before"){
//			$("#ZtreeMenuDivID").remove();
			this.confirCloseModel();
		}else if(bz == "add-after"){
//			$("#ZtreeMenuDivID").remove();
			this.confirCloseModel();
		}else if(bz == "add-sub"){
//			$("#ZtreeMenuDivID").remove();
			this.confirCloseModel();
		}else if(bz == "add-top"){
//			$("#ZtreeMenuDivID").remove();
			this.confirCloseModel();
		}else if(bz == "edit-node"){
//			$("#ZtreeMenuDivID").remove();
			this.confirCloseModel();
		}
	};
	
	
	
	this.showModel=function(menuName,menuValue,treeID,bz){
		commutils.closeWins('_moduleTreeWindow');
		commutils.createDiv("_moduleTreeWindow");
			function show(){
				var titleHeight=80;
				var bareHeight=80;
				
				$('#_header').focus();
				var height=$(window).height();
				height=200;
				var width=$(window).width();
				width=400;
				$('#_modelTreeForms').css('height',(height-titleHeight-bareHeight)).css('overflow-y','auto');
				
				$('#_moduleTreeWindow').dialog({
					autoOpen: false,
					modal:true,
					//show: "explode",
					//hide: "explode",
					//width:width,
					animate: true,
					maxHeight:height,
					minWidth:450,
					maxWidth:450,
					bgiframe:true,
					resizable:false,
					close: function(event, ui){
						
					}
				});
				$('#_moduleTreeWindow').dialog('open');
				$('.ui-dialog-titlebar').hide();
			}
			$('#_moduleTreeWindow').load(ctxPath+"/front/atlastree/form/createNodeForm.htm?d="+new Date().getTime(),{menuName : menuName, menuValue : menuValue, treeID : treeID,bz : bz },show);
			
		};
		
		this.confirCloseModel = function(){
			$('#_moduleTreeWindow').html('');
				$('.formError').remove();
				$('#_moduleTreeWindow').dialog('close');
				$('#_moduleTreeWindow').dialog('destroy');
		};
		
		this.closeModel=function(){
			function callBack(){
				$('#_moduleTreeWindow').html('');
				$('.formError').remove();
				$('#_moduleTreeWindow').dialog('close');
				$('#_moduleTreeWindow').dialog('destroy');
			}
			RD.confirm("确定取消吗?",{callBackFunc:callBack});
		}
		
		
		
		
		
	/**
	 * 添加界面保存 按钮
	 * @param {} bz
	 */
	this.saveFormNodeByRMenu = function(bz,treeID){ 
	    var curTreeNode = null;
	    if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).RightMenuCurrentTreeNodeObj){
	    	curTreeNode = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).RightMenuCurrentTreeNodeObj.treeNode;
	    }
	    
	    var menuName = $("#menuNameInputID").val();
	    if(!menuName || menuName == ""){
	    	return;
	    }
	    
		if(bz == "add-before"){
			var mapObj = {};
			mapObj.treeType = treeType;
			mapObj.groupID = "-1";
			mapObj.atlasName = menuName;
			mapObj.content = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).noeZTreeControl.getReflshTreeCondition();
			mapObj.pid = curTreeNode.pid;
			mapObj.insertBZ = "add-before";
			mapObj.insertNodeID = curTreeNode.id;
			
			
			var FData = {mapObj : JSON.stringify(mapObj)};
			$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).actionName+"!insertTree.do",FData,function(res){ 
					eval("var text="+res);
					if(text.success){
						NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).reAsyncChildNode(curTreeNode.getParentNode(),"refresh");
						return ;
					}else{
						 alert("操作失败，请重试!");
						return ;
					}
			});
		
			
		/*	var node = new NoeZTreeControl_TreeNode();
			node.pid = curTreeNode.pid;
			node.name = menuName;
			
			this.addNodes(curTreeNode.getParentNode(),node,true); */
//			this.reAsyncChildNode(curTreeNode.getParentNode(),"refresh");
			
		}else if(bz == "add-after"){
			var mapObj = {};
			mapObj.treeType = treeType;
			mapObj.groupID = "-1";
			mapObj.atlasName = menuName;
			mapObj.content = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).noeZTreeControl.getReflshTreeCondition();
			mapObj.pid = curTreeNode.pid;
			mapObj.insertBZ = "add-after";
			mapObj.insertNodeID = curTreeNode.id;
			
			
			var FData = {mapObj : JSON.stringify(mapObj)};
			$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).actionName+"!insertTree.do",FData,function(res){ 
					eval("var text="+res);
					if(text.success){
						NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).reAsyncChildNode(curTreeNode.getParentNode(),"refresh");
						return ;
					}else{
						 alert("操作失败，请重试!");
						return ;
					}
			});
			
			/*var node = new NoeZTreeControl_TreeNode();
			node.pid = curTreeNode.pid;
			node.name = menuName;
			
			this.addNodes(curTreeNode.getParentNode(),node,true); */
//			this.reAsyncChildNode(curTreeNode.getParentNode(),"refresh");
			
		}else if(bz == "add-sub"){
			var mapObj = {};
			mapObj.treeType = treeType;
			mapObj.groupID = "-1";
			mapObj.atlasName = menuName;
			mapObj.content = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).noeZTreeControl.getReflshTreeCondition();
			mapObj.pid = curTreeNode.id;
			mapObj.insertBZ = "add-sub";
			mapObj.insertNodeID = curTreeNode.id;
			
			
			var FData = {mapObj : JSON.stringify(mapObj)};
			$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).actionName+"!insertTree.do",FData,function(res){ 
					eval("var text="+res);
					if(text.success){
						curTreeNode.isParent = true;
						NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).reAsyncChildNode(curTreeNode,"refresh");
						return ;
					}else{
						 alert("操作失败，请重试!");
						return ;
					}
			});
			
			/*var node = new NoeZTreeControl_TreeNode();
			node.pid = curTreeNode.id;
			node.name = menuName;
			
			this.addNodes(curTreeNode,node,true);*/
		//	this.reAsyncChildNode(curTreeNode,"refresh");
		}else if(bz == "add-top"){
			var mapObj = {};
			mapObj.treeType = treeType;
			mapObj.groupID = "-1";
			mapObj.atlasName = menuName;
			mapObj.content = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).noeZTreeControl.getReflshTreeCondition();
			mapObj.pid = "0";
			mapObj.insertBZ = "add-top";
			mapObj.insertNodeID = "0";
			
			var FData = {mapObj : JSON.stringify(mapObj)};
			$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).actionName+"!insertTree.do",FData,function(res){ 
					eval("var text="+res);
					if(text.success){
						NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).reAsyncChildNode(null,"refresh");
						return ;
					}else{
						alert("操作失败，请重试!");
						return ;
					}
			});
			/*var node = new NoeZTreeControl_TreeNode();
			node.pid = "";
			node.name = menuName;
			
			this.addNodes(null,node,true);*/
		//	this.reAsyncChildNode(curTreeNode,"refresh");
		}else if(bz == "edit-node"){
			var FData = {nodeID : NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).currentEditNode.id, nodeName : menuName};
			$.post(ctxPath+NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).actionName+"!updateTreeNode.do",FData,function(res){ 
					eval("var text="+res);
					if(text.success){
						NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).reAsyncChildNode(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).currentEditNode.getParentNode(),"refresh");
						return ;
					}else{
						 alert("操作失败，请重试!");
						return ;
					}
			});
			
		}
		NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).removeAdddNodeFormByRMenu(bz);
	};
	
	/**
	 * 添加界面 取消 按钮
	 * @param {} bz
	 */
	this.cancelFormNodeByRMenu = function(bz,treeID){
		NoeZTreeControl_OP_Map.getCurrentControl_OP(treeID).removeAdddNodeFormByRMenu(bz);
	};
	
	/**
	 * 添加节点
	 * @param {} parentNode
	 * @param {} newNodes
	 * @param {} isSilent
	 */
	this.addNodes = function(parentNode,newNodes,isSilent){
		this.noeZTreeControl.zTree.addNodes(parentNode,newNodes,isSilent);
	};
	
	this.reAsyncChildNode = function(node,model){
		
		this.noeZTreeControl.zTree.setting.callback.onAsyncSuccess = this.onAsyncSuccessWhenOpResultReflsh;
		
		if(!model){
			model = "refresh";
		}
		this.noeZTreeControl.zTree.reAsyncChildNodes(node,model);
	};
	
	/**
	 * 操作树形节点时 保存操作，需要刷新某个节点，以观看效果，这时需要用到该加载成功函数
	 * @param {} event
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.onAsyncSuccessWhenOpResultReflsh = function(event, treeId, treeNode){
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.check){
			if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.check.enable){
			
			if(treeNode && treeNode.childs){
				    for(var i=0; i<treeNode.childs.length; i++){
				    	NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.checkNode(treeNode.childs[i],treeNode.checked,false,false);
					}
				}
			}
		}
		
		if(!treeNode){
			return;
		}
		
		var nodes = treeNode.childs; 
		if(!nodes){
			return;
		}
	};
	
	/**
	 * 树节点加载前  需要做的事件(添加 combobox参数)
	 * @param {} treeId
	 * @param {} treeNode
	 */
   this.beforeAsync = function(treeId, treeNode){ 
   	
   		if(this.currentPageIsReflush){
   			
			this.currentPageIsReflush = false; 
			return true;
   		}
   		
		var extendColPar = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.getReflshTreeCondition();
		if(!extendColPar){
			extendColPar = "";
		}
		
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree){
			var otherParObj = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.async.otherParam;
		    otherParObj.extendColPar = extendColPar;
		    
		    var isDel = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.getShowCheID();
		    var flagUse = 1;
		    if(isDel){
		       flagUse = 0;
		    }
		    
		    otherParObj.flagUse = flagUse;
		}
		
		return true;
	};
	
	/**
	 * 增加 查询条件常量编码值
	 * @param {} constCode
	 */
   this.addTreeConstCode = function(constCode){
		if(!this.treeConstCodeArr){
			this.treeConstCodeArr = new Array();
		}
		this.treeConstCodeArr.push(constCode);
		
	};
	
	/**
	 * 初始化 下拉框数组
	 */
	this.initTreeConstCode = function(){
		this.treeConstCodeArr = null;
	};
	
	/**
	 * checkbox tree 勾选之前，要展开所有该节点的下级节点
	 * @param {} treeId
	 * @param {} treeNode
	 */
	this.onCheck = function(event, treeId, treeNode){
		if(treeNode.checked == false){//取消选中状态
			return;
		}
		NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).expandNodeByAscyn(treeId, treeNode);
		return;
	};
	
	this.expandNodeByAscyn = function(treeId, treeNode){
		if(!treeNode){
			return;
		}
		if(NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.async.otherParam.async){ //异步树
			if(treeNode.childs && treeNode.childs.length > 0){//说明已经 异步加载过该节点
				for(var i=0; i<treeNode.childs.length; i++){
					NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).expandNodeByAscyn(treeId,treeNode.childs[i]);
				}
				NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.expandNode(treeNode,true,true);
				
			}else{//没有异步加载过该节点
				 NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.setting.callback.onAsyncSuccess = NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).onAsyncSuccess;
				 NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).reAsyncChildNode(treeNode,"refresh");
			}
		}else{//同步树
			NoeZTreeControl_OP_Map.getCurrentControl_OP(treeId).noeZTreeControl.zTree.expandNode(treeNode,true,true);
		}
	};
	
	/**
	 * 得到被勾选的全部节点
	 * @param {} isChecked -- 是否勾选上
	 * @param {} isContainParent --是否包含父节点
	 */
	this.getCheckedNodes = function(isChecked,isContainParent){
		var nodes =  this.noeZTreeControl.zTree.getCheckedNodes(true);
		if(!isContainParent){
			if(nodes){
				var arr = new Array();
				for(i=0; i<nodes.length; i++){
					if(!nodes[i].isParent){
						arr.push(nodes[i]);
					}
				}
				
				return arr;
			}else{
				return nodes;
			}
		}else{
			return nodes;
		}
	};
	
	/**
	 * 得到被勾选的全部节点ID
	 * @param {} isChecked -- 是否勾选上
	 * @param {} isContainParent --是否包含父节点
	 */
	this.getCheckedNodeIDs = function(isChecked,isContainParent){
		var nodes = this.getCheckedNodes();
		if(nodes){
			var arr = new Array();
			for(i=0; i<nodes.length; i++){
				arr.push(nodes[i].id);
			}
			return arr.join(",");
		}
		
		return "";
	}
	
	this.getCheckedNodeIDsByParent = function(){
		var nodes = this.getCheckedNodes(true);
		if(nodes){
			var arr = new Array();
			for(i=0; i<nodes.length; i++){
				var str = nodes[i].id;
				if(nodes[i].getParentNode()){
					str += "," + this.getParentNodeID(nodes[i].getParentNode());
				}
				arr.push(str);
			}
			return arr.join(";");
		}
		return "";
	},
	
	this.getParentNodeID = function(node){
		if(node.getParentNode()){
			return node.id+","+this.getParentNodeID(node.getParentNode());
		}
		return node.id;
	}
	
};

/**
 * 构造函数 树形
 * @param {} treeDefine
 */
function NoeZTreeControl(treeDefine){
	this.zTree = null;
	this.NoeZTreeCP = new NoeZTreeControl_OP();
	this.init(treeDefine);
}

/**
 * 树形的初始化
 * @param {} treeDefine
 */
NoeZTreeControl.prototype.init = function(treeDefine){
	this.NoeZTreeCP.actionName = treeDefine.NoeZTreeCP.actionName;
	if(treeDefine.NoeZTreeCP.treeConstCode){
		this.NoeZTreeCP.treeConstCodeArr = treeDefine.NoeZTreeCP.treeConstCode;
	}else{
		this.NoeZTreeCP.treeConstCodeArr = new Array();
	}
	
	if(treeDefine.selectIndirModel){
		this.NoeZTreeCP.selectIndirModel = treeDefine.selectIndirModel;
	}
	
	NoeZTreeControl_OP_Map.map.put(treeDefine.applyTo,this.NoeZTreeCP);
	this.NoeZTreeCP.zTreeControlName = treeDefine.zTreeControlName;
	
	
	var treeApplyTo = treeDefine.applyTo;
	var treeModel = treeDefine.treeModel;
	this.NoeZTreeCP.ctxPath = treeDefine.ctxPath;
	
	var setting = treeDefine.setting;
	
	if(setting.async){
		if(setting.async.otherParam){
			if(setting.async.otherParam.async){
				this.NoeZTreeCP.isAsyncTreeNode = true;
			}
		}
	}
	
	var view = {};
	
	if(!treeModel){
		treeModel = "opView";
	}
	
	if(treeModel == "opEdit"){ 
		
		view = {
				addHoverDom: this.NoeZTreeCP.addHoverDom,
				removeHoverDom: this.NoeZTreeCP.removeHoverDom
		};
	
	}
	
	 if(setting.view){
	      $.extend(view,setting.view);
	 }
	   
	setting.view = view;
	
	setting.view.fontCss = this.getFontCss;
	
	if(setting.callback){
		if(setting.callback.onAsyncSuccess){
			this.NoeZTreeCP.onAsyncSuccessFun = setting.callback.onAsyncSuccess;
		}
	}else{
		setting.callback = {};
	}
	
	if(setting.callback.onClick){//单击事件
		this.NoeZTreeCP.onClickByUser = setting.callback.onClick;
	}
	setting.callback.onClick = this.NoeZTreeCP.onClick;
	
	if(treeModel == "opEdit"){ 
		if(!setting.callback.onRightClick){//右键菜单事件
	
			setting.callback.onRightClick = this.NoeZTreeCP.onRightClick;
		}
	
		if(!setting.callback.beforeRightClick){//右键菜单事件
		
			setting.callback.beforeRightClick = this.NoeZTreeCP.beforeRightClick;
		}
	}
	
	
	if(!setting.callback.beforeAsync){//树节点加载前的事件
	  
		setting.callback.beforeAsync = this.NoeZTreeCP.beforeAsync;
	}
	
	this.NoeZTreeCP.noeZTreeControl = this;
	
	this.NoeZTreeCP.currentPageIsReflush = true; 
	setting.async.otherParam.extendColPar = this.getReflshTreeCondition();//第一次页面刷新 树还没有形成 加载前的条件函数失效  需要重新初始化
	
    var isDel = this.getShowCheID();
    var flagUse = 1;
    if(isDel){
        flagUse = 0;
    }
	setting.async.otherParam.flagUse = flagUse;    
	
	if(setting.check){
		if(setting.check.enable){
			if(!setting.check.chkboxType){
				setting.check.chkboxType = { "Y" : "ps", "N" : "ps" };
			}
			
			if(!setting.callback.beforeCheck){
				setting.callback.onCheck = this.NoeZTreeCP.onCheck;
			}
			
//			setting.callback.onAsyncSuccess = this.NoeZTreeCP.onCheckedAsyncSuccess;
		}
	}
	
	this.zTree = $.fn.zTree.init($("#"+treeApplyTo), setting);
}

/**
 * 展开所有节点
 */
NoeZTreeControl.prototype.expandAll = function(){
	
	if(this.NoeZTreeCP.isAsyncTreeNode){
		if(!this.zTree.setting.callback){
			this.zTree.setting.callback = {};
		}
	
		this.zTree.setting.callback.onAsyncSuccess = this.NoeZTreeCP.onAsyncSuccess;
		
		var rootNodes = this.getRootNodes();
		
		for(var i=0; i<rootNodes.length; i++){
			this.zTree.reAsyncChildNodes(rootNodes[i],"refresh");
		}
	}else{
		this.zTree.expandAll(true);
	}
	
}

/**
 * 展开所有已勾选的节点
 */
NoeZTreeControl.prototype.expandAllChecked = function(){
	
	if(this.NoeZTreeCP.isAsyncTreeNode){
		if(!this.zTree.setting.callback){
			this.zTree.setting.callback = {};
		}
	
		this.zTree.setting.callback.onAsyncSuccess = this.NoeZTreeCP.onCheckedAsyncSuccess;
		
		var rootNodes = this.getRootNodes();
		
		for(var i=0; i<rootNodes.length; i++){
			if(rootNodes[i].checked){
				this.zTree.reAsyncChildNodes(rootNodes[i],"refresh");
			}
		}
	}else{
		this.zTree.expandAll(true);
	}
	
}

/**
 * 折叠全部节点
 */
NoeZTreeControl.prototype.collapseAll = function(){
	this.zTree.expandAll(false);
}

/**
 * 获取根节点
 * @return {}
 */
NoeZTreeControl.prototype.getRootNodes = function(){
	return this.zTree.getNodes();
}


/**
 * 注册 每一层 树结构涉及的菜单对象名称
 * @param {} menuNameArr
 */
NoeZTreeControl.prototype.registerRMenuObj = function(menuNameArr){
	if(!menuNameArr){
		return;
	}
	
	this.NoeZTreeCP.rightMenuNames = menuNameArr;
	
	//默认为 用户填写的菜单项的长度
	this.NoeZTreeCP.sumSubChildLevel = menuNameArr.length;
}

/**
 * 增加 右键菜单
 * @param {} index
 * @param {} rMenuArr
 * @return {}
 */
/*NoeZTreeControl.prototype.addRMenuOP = function(index,rMenuArr){
	if(!this.NoeZTreeCP.rightMenuMap){
		this.NoeZTreeCP.rightMenuMap = new Map();
	}
	
	this.NoeZTreeCP.rightMenuMap.put(index,rMenuArr);
}*/

/**
 * 得到系统自定义菜单
 * @param {} index
 * @return {}
 */
/*NoeZTreeControl.prototype.getSystemRMenu = function(index){
	return this.NoeZTreeCP.getSystemRMenu(index);
}*/



/**
 * 当前右键菜单触发的 node对象 {event : event, treeId : treeId, treeNode : treeNode}
 * @return {}
 */
NoeZTreeControl.prototype.getRightMenuCurrentTreeNodeObj = function(){
	return this.NoeZTreeCP.RightMenuCurrentTreeNodeObj;
}

/**
 * 是否启用  系统 自带的 右键菜单
 * @param {} isEnable
 */
NoeZTreeControl.prototype.setEnableRightSysMenu = function(isEnable){
	this.NoeZTreeCP.enableRightSysMenu = isEnable;
}

/**
 * 可以添加多少级下级菜单
 * @param {} sumSubChildLevel
 */
NoeZTreeControl.prototype.setSumSubChildLevel = function(sumSubChildLevel){
	this.NoeZTreeCP.sumSubChildLevel = sumSubChildLevel;
}


/**
 * 增加 查询条件常量编码值
 * @param {} constCode
 */
NoeZTreeControl.prototype.addTreeConstCode = function(constCode){
	if(!this.NoeZTreeCP.treeConstCodeArr){
		this.NoeZTreeCP.treeConstCodeArr = new Array();
	}
	this.NoeZTreeCP.treeConstCodeArr.push(constCode);
	
}

/**
 * 查询 重新加载当前树
 */
NoeZTreeControl.prototype.doQuery = function(){
	this.setReflshTreeCondition();
}

/**
 * 设置树重新加载的条件
 */
NoeZTreeControl.prototype.setReflshTreeCondition = function(){
	this.NoeZTreeCP.reAsyncChildNode(null,"refresh");
}

/**
 * 得到常量 下拉框的条件
 */
NoeZTreeControl.prototype.getReflshTreeCondition = function(){ 
	if(this.NoeZTreeCP.treeConstCodeArr){
		var conArr = new Array();//查询条件 数组
		
		for(var i=0; i<this.NoeZTreeCP.treeConstCodeArr.length; i++){
			var constCode = this.NoeZTreeCP.treeConstCodeArr[i];
			var selectObj = $("#"+constCode+this.NoeZTreeCP.selectIndirModel);
			var name = selectObj.attr("name");
			var value = selectObj.val();
			if(value){
				if(value != "-1"){//全部的时候 或者为空的时候 需要加载全部树节点 
					conArr.push(name + ":" + value);
				}
			}
			
		}
		
		var conStr = conArr.join("|");
		return conStr;
	}
	
	return "";
}

/**
 * 树 增加 顶层节点
 */
NoeZTreeControl.prototype.addTreeTopNode = function(){
	this.NoeZTreeCP.showAddNodeFormByRMenu("add-top");
}

/**
 * 判断 页面是否 选择了 是否删除 checkbox
 * @return {Boolean}
 */
NoeZTreeControl.prototype.getShowCheID = function(){
	if($("#showDelCheID").attr("checked")=='checked'){
		return true;
	}
	return false;
}

/**
 * 树加载后 显示样式
 * @param {} treeId
 * @param {} node
 */
NoeZTreeControl.prototype.getFontCss = function(treeId, node){
	if(node.flagUse == 0){
		return {color : 'red'};
	}
	return {};
}
NoeZTreeControl.prototype.getSelectedNodes = function(){
	return this.zTree.getSelectedNodes();
}
/**
 * 取消所有选中节点
 */
NoeZTreeControl.prototype.cancelAllNode = function(callBack){
	this.zTree.cancelSelectedNode();
	if(callBack){
		callBack();
	}
}

/**
 * 得到被勾选的全部节点
 * @param {} isChecked -- 是否勾选上
 * @param {} isContainParent --是否包含父节点
 */
NoeZTreeControl.prototype.getCheckedNodes = function(isChecked,isContainParent){
	return this.NoeZTreeCP.getCheckedNodes(isChecked,isContainParent);
}

/**
 * 得到被勾选的全部节点ID
 * @param {} isChecked -- 是否勾选上
 * @param {} isContainParent --是否包含父节点
 */
NoeZTreeControl.prototype.getCheckedNodeIDs = function(isChecked,isContainParent){
	return this.NoeZTreeCP.getCheckedNodeIDs(isChecked,isContainParent);
}

NoeZTreeControl.prototype.getCheckedNodeIDsByParent = function(){
	return this.NoeZTreeCP.getCheckedNodeIDsByParent();
}

/**
 * 在同级 前面增加节点
 */
NoeZTreeControl.prototype.addBeforeButton = function(){
	if(!this.setRightMenuCurrentTreeNodeObj()){
		return;
	}
	this.NoeZTreeCP.getSystemMenuClickFun("add-before");
}

/**
 * 在同级 后面增加节点
 */
NoeZTreeControl.prototype.addAfterButton = function(){
	if(!this.setRightMenuCurrentTreeNodeObj()){
		return;
	}
	this.NoeZTreeCP.getSystemMenuClickFun("add-after");
}

/**
 * 增加 下级节点
 */
NoeZTreeControl.prototype.addSubButton = function(){
	if(!this.setRightMenuCurrentTreeNodeObj()){
		return;
	}
	this.NoeZTreeCP.getSystemMenuClickFun("add-sub");
}

/**
 * 设置 增加(同级，下级) 按钮  选择节点对象，适配右键菜单
 */
NoeZTreeControl.prototype.setRightMenuCurrentTreeNodeObj = function(){
	var selectNodes = this.zTree.getSelectedNodes();
	if(!selectNodes || selectNodes.length != 1){
		RD.alert("请选取一个节点添加");
		return false;
	}
	this.NoeZTreeCP.RightMenuCurrentTreeNodeObj = {treeId : this.zTree.setting.treeId, treeNode : selectNodes[0]};
	return true;
}

//--------------------------------
/**
 * jQuery ztree node  对应后台 json数据类的数据格式
*/

function NoeZTreeControl_TreeNode(){
	this.id = '';
	this.pid = '';
	this.name = '';
	this.open = false;
	this.levelCode = '';
	this.isParent = false;
};

//保存当前操作的树控制器
var NoeZTreeControl_OP_Map = {
	map : new Map(),
	getCurrentControl_OP : function(treeID){
		return NoeZTreeControl_OP_Map.map.get(treeID);
	}
}